from google.appengine.ext import db
from google.appengine.ext.db import StringProperty
import Consts

####
#properties with '_' prefix are used foe server only.
#_source_type - user, auto_parsing
#_source - user name, website.
####


class SaveZoneDataBaseObject(db.Model):
    _source_type = db.StringProperty()
    _source = db.StringProperty()
    _dateAdded = db.DateProperty(auto_now_add=True, indexed = False)
    #do not use it, but save a copy.
    _deleted = db.IntegerProperty(default = 0)
    
class Business(SaveZoneDataBaseObject):
    name = db.StringProperty()
    country = db.StringProperty()
    city = db.StringProperty()
    street = db.StringProperty()
    street_num = db.StringProperty()
    full_address = db.StringProperty(multiline = True)
    business_type = db.StringProperty()
    website = db.StringProperty(indexed = False)
    pic_link = db.StringProperty(indexed = False)
    more_info = db.StringProperty(indexed = False)
    latitude = db.StringProperty(indexed = False)
    longitude = db.StringProperty(indexed = False)
    
class Deal(SaveZoneDataBaseObject):
    business_item = db.ReferenceProperty(Business)
    name = db.StringProperty()
    deal_type = db.StringProperty()
    #date = db.StringProperty()
    days_bitmap = db.IntegerProperty(default = Consts.ALL_DAYS)
    time = db.StringProperty()
    time_delta = db.StringProperty()
    deal_info = db.StringProperty(indexed = False, multiline=True)
    #sum of all the rating
    rate_sum = db.IntegerProperty(indexed = False, default = 0)
    #number of people which rated
    rate_num = db.IntegerProperty(default = 0)
    #number of people which rate the cost level
    cost_level_num = db.IntegerProperty(indexed = False, default = 0)
    #sum of all cost level
    cost_level_sum = db.IntegerProperty(indexed = False, default = 0)
    #num of users reported this app as fake
    fake_num = db.IntegerProperty(default = 0)
    

#comments for a deal
class Comment(SaveZoneDataBaseObject):
    deal_item = db.ReferenceProperty(Deal)
    comment_str = db.StringProperty(indexed = False)
    #sum of all the rating
    comment_rate_sum = db.IntegerProperty(indexed = False, default = 0)
    #number of people which rated
    comment_rate_num = db.IntegerProperty(indexed = False, default = 0)
    comment_date = db.DateTimeProperty(auto_now_add=True, indexed = False)
    comment_rate = db.IntegerProperty(indexed = False, default = 0)
    comment_cost_level = db.IntegerProperty(indexed = False, default = 0)

class User(SaveZoneDataBaseObject):
    user_name = db.StringProperty(indexed = False)
    email = db.StringProperty()
    credit = db.IntegerProperty(indexed = False)
    likes = db.TextProperty(indexed = False, default="")
    likes_int = db.TextProperty(indexed = False, default="")

class CheckIn(db.Model):
    business = db.ReferenceProperty(Business)
    user_name = db.StringProperty(indexed = False)
    email = db.StringProperty(indexed = False)
    pic = db.TextProperty(indexed = False)
    facebook_link = db.StringProperty(indexed = False)
    _dateAdded = db.DateTimeProperty(auto_now_add=True, indexed = False)
    
#memory for analyzed data
class NextUrl(db.Model):
    http_name = StringProperty(indexed = False)
    next_url = StringProperty(indexed = False) 